import path from 'path'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'

import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

const pathSrc = path.resolve(__dirname, 'src')

export default ({ mode }) => {
  return defineConfig({
    base: './',
    resolve: {
      alias: {
        '~/': `${pathSrc}/`
      },
    },
    server: {
      proxy: {
        '/ic-openapi': {
          target: loadEnv(mode, process.cwd()).VITE_APP_URL,	//实际请求地址
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/ic-openapi/, '/ic-openapi')
        },
      }
    },
    plugins: [
      vue(),
      Components({
        // allow auto load markdown components under `./src/components/`
        extensions: ['vue', 'md'],
        // allow auto import and register components used in markdown
        include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
        resolvers: [
          ElementPlusResolver({
            importStyle: 'sass',
          }),
        ],
        dts: 'src/components.d.ts',
      }),
    ],
  })
}